<?php
require_once(dirname(__FILE__)."/../inc/common.php");
/*******************************************************************************************
'*******************************************************************************************/
if (paramset==0 || runMode=="forgedStatic"){
	$paras = replaceStr(QUERY_STRING,fileSuffix,'');
	$page=$paras;
}else{
	$page=getForm(parampage,"both") ;
}

if (empty($page)) {
	$page=1;
} else {
	if (is_numeric($page)) { $page = intval($page); } else { echoSaveStr("safe");exit();}
}
GetTopicById($page);

function GetTopicById($page){
	global $t1;
	$x = DJCMS_TEMPLATE."topicindex.html";
	$r = DB::fetch_first("SELECT count(*) as number FROM ".DB::table('topic')." ORDER BY m_sort ASC");
    $TotalResult = $r['number'];
	$pSize = getPageSizeOnCache($x, "topicindex", "topindex.html");if (empty($pSize)) $pSize=12;
	$cacheName = "parse_tp_";
	if (cacheStart==1){
		if (djcms::$content = memory('get', $cacheName)) {
        } else {
            parseTopicIndex($x);
			memory('set', $cacheName, djcms::$content);
        }
	} else {
			parseTopicIndex($x);
	}
	$pCount = ceil($TotalResult/$pSize);
	djcms::$content=replaceStr(djcms::$content,"{topicindexlist:page}",$page);
	djcms::parseTopicIndex($page,$pCount);
	djcms::parseIf();
	echo replaceStr(djcms::$content,"{yh:runinfo}",getRunTime($t1));
}

function parseTopicIndex($x)
{
	djcms::$content=loadFile($x);
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::$content=replaceCurrentTypeId(djcms::$content);
	djcms::$content=replaceTopicId(djcms::$content);
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
}
?>
